#include <bits/stdc++.h>

using namespace std;

class Solution {
public:
	bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {
		vector<vector<int>> adjacencyList(numCourses);
		vector<int> degree(numCourses, 0);
		vector<bool> vis(numCourses);
		for (auto& prerequisity : prerequisites) {
			adjacencyList[prerequisity[1]].emplace_back(prerequisity[0]);
			degree[prerequisity[0]]++;
		}

		auto begin_degree = begin(degree), end_degree = end(degree);
		while (true) {
			int idx = -1;
			for (int i = 0; i < numCourses; i++)
				if (degree[i] == 0 && !vis[i]) idx = i;
			if (idx == -1) break;
			for (int i: adjacencyList[idx])
				degree[i]--;
		}

		for (int i: degree)
			if (i != 0) return false;

		return true;
	}

private:
};

int main()
{
	Solution solution;
	return 0;
}
